/*
 * example2.c
 *
 *  Created on: Apr 1, 2011
 *      Author: makkalot
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "fibthread.h"

void* foo(void* p);
void* bar(void* p);

int main(int argc,char *argv[]){

	int i;

	for(i = 0; i < FIBTHREAD_THREADS_MAX; i++){
		if(i%2==0){
			if(fibthread_create(NULL,NULL,foo,NULL)<0){
				printf("Error when creating foo \n");
				exit(EXIT_FAILURE);
			}
		}
		else{
			if(fibthread_create(NULL,NULL,bar,NULL)<0){
				printf("Error when creating foo \n");
				exit(EXIT_FAILURE);
			}
		}
	}

	fibthread_loop();

	return 0;
}

void* foo(void* p){
	int i;
	for(i=0;i<1000000;i++){
		//printf("Hello from foo %d \n",i);
		printf("Hello from foo Thread %d --> Counter : %d\n",fibthread_self(),i);
		//sleep(2);
		fibthread_yield();
	}
	return NULL;
}


void* bar(void* p){
	int i;
	for(i=0;i<1000000;i++){
		printf("Hello from bar Thread %d --> Counter : %d\n",fibthread_self(),i);
		fibthread_yield();
	}
	return NULL;
}
